<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" :rows="2" :collapse="true" :labelWidth="100" @filterChange="getBusiness" @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      ref="businessMangerTable"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      exportFileName="维修业务导出表.xlsx"
      :rowstyles="styleList"
      :cellstyles="fetchRowstyles"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="columns => (this.selectColumns = columns)"
      :onSyncTableData="syncDataChange"
    >
      <template slot="controls">
        <!-- <el-button v-show="btnExportType" size="small" type="primary" @click="exportClick">导出</el-button> -->
        <el-button size="small" type="primary" @click="electronization">合并打印</el-button>
      </template>
    </FilterTable>

    <p>当前系统时间 - 约定交车时间 > 预交车预留时间 且未提交结算的，红底显示</p>

    <!-- 生成索赔单号 -->
    <BaseDialog :visible.sync="claim" title="生成索赔单号" destroyOnClose width="300px" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <claimModel :list="this.selectColumns" @closeDialog="closeDialog"></claimModel>
    </BaseDialog>

    <!-- 查询明细 -->
    <Drawer :visible.sync="labour" title="明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <labourModel :list="selectData" @closeDialog="closeDialog"></labourModel>
    </Drawer>

    <!-- 查看日志 -->
    <BaseDialog :visible.sync="orderLog" title="工单日志信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <orderLogModel :list="this.selectColumns" @closeOrderLog="closeOrderLog"></orderLogModel>
    </BaseDialog>

    <BasePrint ref="print" :data="printList" template="templatePrintFeeForBatch" />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import { searchRoleByCode, searchRoleByCodes } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import { exportExcelFile } from '@/utils/index';
import { queryRepairBusiness, modelsDict, unLockRepairOrder, repairBussinessExportExcel } from '@/api/repair/repairReception/repairBusinessManger';
import { getPinpSelect, getChexSelect, getCheModelSelect } from '@/api/repair/repairReception/customer';
import claimModel from '@/pages/repair/repairReception/repairBusinessManger/claimModel.vue';
import labourModel from '@/pages/repair/repairReception/repairBusinessManger/labourModel';
import orderLogModel from '@/pages/repair/repairReception/repairBusinessManger/orderLogModel';
import { getBrand, getSeries, getModel, getRegion, getBxgsSelect } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getProvince, getCitys, getDistrict } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import { getWxlxSelect, getSystemDefault, getportal } from '@/api/repair/repairReception/customer';
import { getUser } from '@/assets/js/auth';
import { roPrintPdf } from '@/api/repair/queryStatistics/queryAccounts';
import { getRepairOrderHBPrintInfo, getRoLabourDtls } from '@/api/repair/repairReception/customer';
import { queryCompanyInforById } from '@/api/repair/repairReception/feesSettlement';
import { notifyAction } from '@/utils';
import { getAllUser } from '@/api/finance/advancesReceived/register';

export default {
  name: 'businessManger',
  components: {
    claimModel,
    labourModel,
    orderLogModel
  },
  mixins: [dictionary],
  data() {
    // this.isDisabled = true; // 扩展查询
    this.isOpenDate = true; // 预计交车
    this.selectData = {};
    return {
      topFilterList: this.createTopFilters(),
      selectColumns: [],
      columns: this.createTableColumns(),
      fetchApi: queryRepairBusiness,
      fetchParams: {
        xhrAbort: true
      },
      claim: false,
      order: false,
      labour: false,
      orderLog: false,
      brandCode: '',
      address2: {
        list1: this.createRegionList(),
        list2: [],
        list3: []
      },
      styleList: [],
      fetchRowstyles: [], // 指定单个样式
      consultantRes: {},
      printList: {},
      btnExportType: true,
      systemOptionAuthParams: {
        isCanExportExcel: '10041001' // 是否可以到处excel
      },
      systemDefalutParams: {
        yjcylTime: '', // 预交车预留时间
        orderStatus: '' // 判断是否为一车一单状态
      },
      visible2: false,
      finalUrl: '',
      paramss: {
        // portal登录账号
        username: '',
        password: '',
        'login-form-type': 'pwd'
      },
      ownerCode: '', // 经销商代码
      ownerName: '' // 经销商名称
    };
  },

  mounted() {
    this.getBrand();
    this.serviceConsultant();
    // this.getProvine();
    this.getBxgsSelect();
    this.checkSystemOptionAuthParams(); // 页面加载完成校验系统权限参数做相应设置
    this.getWxtypeSelect();
    this.getSystemDefaultValueInfo();
    this.getportal();
    this.getUser();
    // this.getPersonParams();
  },

  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '工单号',
          fieldName: 'roNo',
          onEnter: () => {
            this.getBusiness();
          },
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '电子首保卡号',
          fieldName: 'efwcard',
          placeholder: '请选择',
          initialValue: '',
          hidden: true
        },
        {
          type: 'SELECT',
          label: '工单状态',
          fieldName: 'roStatus',
          placeholder: '请选择',
          itemList: this.createDictList('8049'),
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '服务顾问',
          fieldName: 'serviceAdvisor',
          placeholder: '请选择',
          itemList: [],
          filterable: true,
          initialValue: ''
        },
        {
          label: '选择时间类型',
          type: 'SELECT',
          fieldName: 'dataType',
          initialValue: 'RO_CREATE_DATE',
          itemList: [
            { value: 'RO_CREATE_DATE', text: '工单开单时间' },
            { value: 'FOR_BALANCE_TIME', text: '提交结算时间' },
            { value: 'COMPLETE_TIME', text: '竣工时间' },
            { value: 'DELIVERY_DATE', text: '交车日期' },
            { value: 'BALANCE_CLOSE_TIME', text: '关单日期' },
            { value: 'BALANCE_TIME', text: '结算时间' },
            { value: 'PRINT_RO_TIME', text: '工单打印时间' },
            { value: 'PRINT_BALANCE_TIME', text: '结算单打印时间' }
          ]
        },
        {
          type: 'RANGE_DATE',
          dateType: 'daterange',
          label: '选择日期',
          fieldName: 'dataBeginDate|dataEndDate',
          initialValue: [moment().format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')],
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'brand',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changePinpSelect(val);
          },
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '车系',
          fieldName: 'series',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeChexSelect(val);
          },
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'model',
          placeholder: '请选择',
          itemList: [],
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '维修类型',
          fieldName: 'repairTypeCode',
          placeholder: '请选择',
          itemList: [],
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车主编号',
          fieldName: 'ownerNo',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '是否关单',
          fieldName: 'balanceClose',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '是否结清',
          fieldName: 'payOff',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车主姓名',
          fieldName: 'ownerName',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '交车标识',
          fieldName: 'deliveryTag',
          placeholder: '请选择',
          itemList: this.createDictList('8001'),
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '是否竣工',
          fieldName: 'completeTag',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          type: 'CHECKBOX',
          fieldName: 'isCheckPreDeliverVehicle',
          label: '预计交车时间',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          initialValue: '',
          change: val => {
            this.openRangeDate(val);
          }
        },
        {
          type: 'RANGE_DATE',
          label: '选择交车时间',
          fieldName: 'checkPreDeliverVehicleBeginDate|checkPreDeliverVehicleEndDate',
          valueFormat: 'yyyy-MM-dd HH:mm:ss',
          initialValue: [],
          disabled: this.isOpenDate
        },

        {
          type: 'SELECT',
          label: '是否含增项',
          fieldName: 'isContainAdd',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '保险公司',
          fieldName: 'insuranceCompany',
          placeholder: '请选择',
          itemList: [],
          initialValue: ''
        },
        {
          type: 'TEXT_AREA',
          label: '电子首保卡备注',
          fieldName: 'remark1',
          placeholder: '请选择',
          initialValue: '',
          hidden: true
        }
        // {
        //   type: 'INPUT',
        //   label: '备注',
        //   fieldName: 'remark',
        //   placeholder: '请选择',
        //   initialValue: ''
        // }
        // {
        //   type: 'CHECKBOX',
        //   fieldName: 'isExtendQuery',
        //   label: '是否扩展查询',
        //   initialValue: '',
        //   change: val => {
        //     this.exQueryBtnState(val);
        //   },
        //   initialValue: ''
        // },
        // {
        //   type: 'INPUT',
        //   label: '地址',
        //   fieldName: 'address',
        //   disabled: this.isDisabled,
        //   initialValue: ''
        // },
        // {
        //   type: 'INPUT',
        //   label: '邮编',
        //   fieldName: 'zipCode',
        //   disabled: this.isDisabled,
        //   initialValue: ''
        // },
        // {
        //   type: 'INPUT',
        //   label: 'E_MAIL',
        //   fieldName: 'eMail',
        //   disabled: this.isDisabled,
        //   initialValue: ''
        // },
        // {
        //   type: 'SELECT',
        //   label: '是否索赔',
        //   fieldName: 'haveClaimTag',
        //   placeholder: '请选择',
        //   disabled: this.isDisabled,
        //   itemList: this.createDictList('1004'),
        //   initialValue: ''
        // },
        // {
        //   type: 'INPUT',
        //   label: '备注',
        //   fieldName: 'reMark',
        //   disabled: this.isDisabled,
        //   initialValue: ''
        // },
        // {
        //   type: 'SELECT',
        //   label: '省份',
        //   fieldName: 'PROVINCE',
        //   placeholder: '请选择',
        //   disabled: this.isDisabled,
        //   itemList: [],
        //   change: val => {
        //     this.provinceChange(val);
        //   },
        //   initialValue: ''
        // },
        // {
        //   type: 'SELECT',
        //   label: '城市',
        //   fieldName: 'CITY',
        //   placeholder: '请选择',
        //   disabled: this.isDisabled,
        //   itemList: [],
        //   change: val => {
        //     this.cityChange(val);
        //   },
        //   initialValue: ''
        // },
        // {
        //   type: 'SELECT',
        //   label: '区县',
        //   fieldName: 'DISTRICT',
        //   placeholder: '请选择',
        //   disabled: this.isDisabled,
        //   itemList: [],
        //   initialValue: ''
        // }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          render: props => {
            return (
              <el-button size="mini" type="text" onClick={() => this.repairLabour(props.row)}>
                明细
              </el-button>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单开单时间',
          dataIndex: 'RO_CREATE_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss'
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 130
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 160
        },
        {
          title: '工单状态',
          dataIndex: 'RO_STATUS',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8049'),
          dictItems: this.createDictList('8049')
        },
        {
          title: '服务顾问',
          dataIndex: 'SERVICE_ADVISOR',
          sorter: true,
          filter: true,
          editable: false,
          filterType: 'checkbox',
          filterItems: [],
          dictItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '新保标识',
          dataIndex: 'IS_XB ',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: 'FD 上传状态',
          dataIndex: 'FD_STATUS',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: 'FD上传日期',
          dataIndex: 'FD_DATE',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          filterType: 'date-range'
        },
        {
          title: 'FD技术经理处理日期',
          dataIndex: 'CLDATTM',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否关单',
          dataIndex: 'BALANCE_CLOSE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '电子首保卡号',
          dataIndex: 'EFW_CARD',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: '150',
          hidden: true
        },
        {
          title: '是否放弃活动',
          dataIndex: 'IS_ABANDON_ACTIVITY',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '交车标识',
          dataIndex: 'DELIVERY_TAG',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8001'),
          dictItems: this.createDictList('8001')
        },
        {
          title: '是否结清',
          dataIndex: 'PAY_OFF',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '是否含增项',
          dataIndex: 'IS_ADD',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '指定技师',
          dataIndex: 'CHIEF_TECHNICIAN',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          editable: false,
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '维修技师',
          dataIndex: 'TECHNICIAN_UNITE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: false,
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
          // render: props => {
          //   return <span>{this.createDictText(props.row.REPAIR_TYPE_NAME, '8000')}</span>
          // }
        },
        {
          title: '结算员',
          dataIndex: 'BALANCE_HANDLER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌',
          dataIndex: 'BRAND_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '车系',
          dataIndex: 'SERIES_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          filterItems: [],
          editType: 'select',
          editItems: [],
          showOverflowTooltip: true
        },
        {
          title: '车型',
          dataIndex: 'MODEL_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          editable: true,
          filterItems: [],
          editType: 'select',
          editItems: [],
          showOverflowTooltip: true
        },
        {
          title: '车主编号',
          dataIndex: 'OWNER_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车主',
          dataIndex: 'OWNER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车主性质',
          dataIndex: 'OWNER_PROPERTY',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8011'),
          dictItems: this.createDictList('8011')
        },
        {
          title: '送修人邮箱',
          dataIndex: 'DELIVERER_EMAIL',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修金额',
          dataIndex: 'REPAIR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          align: 'right',
          render: props => {
            return <span>{Number(props.row.REPAIR_AMOUNT).toFixed(2)}</span>;
          }
        },
        {
          title: '提交结算时间',
          dataIndex: 'FOR_BALANCE_TIME',
          sorter: true,
          filter: true,
          dateFormat: 'YYYY-MM-DD HH:mm',
          filterType: 'date-range'
        },
        {
          title: '交车日期',
          dataIndex: 'DELIVERY_DATE',
          sorter: true,
          filter: true,
          dateFormat: 'YYYY-MM-DD HH:mm',
          filterType: 'date-range'
        },
        {
          title: '是否竣工',
          dataIndex: 'COMPLETE_TAG',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '竣工时间',
          dataIndex: 'COMPLETE_TIME',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm',
          width: 130
        },
        {
          title: '是否待信',
          dataIndex: 'WAIT_INFO_TAG',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '是否待料',
          dataIndex: 'WAIT_PART_TAG',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '是否准时完工',
          dataIndex: 'COMPLETE_ON_TIME',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '进厂行驶里程',
          dataIndex: 'IN_MILEAGE',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '出厂行驶里程',
          dataIndex: 'OUT_MILEAGE',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '预交车时间',
          dataIndex: 'END_TIME_SUPPOSED',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm'
        },
        {
          title: '送修人电话',
          dataIndex: 'DELIVERER_PHONE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '送修人手机',
          dataIndex: 'DELIVERER_MOBILE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '送修人',
          dataIndex: 'DELIVERER',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right',
          render: props => {
            return <span>{Number(props.row.LABOUR_AMOUNT).toFixed(2)}</span>;
          }
        },
        {
          title: '维修材料费',
          dataIndex: 'REPAIR_PART_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right',
          render: props => {
            return <span>{Number(props.row.REPAIR_PART_AMOUNT).toFixed(2)}</span>;
          }
        },
        {
          title: '销售材料费',
          dataIndex: 'SALES_PART_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right',
          render: props => {
            return <span>{Number(props.row.SALES_PART_AMOUNT).toFixed(2)}</span>;
          }
        },
        {
          title: '附加项目费',
          dataIndex: 'ADD_ITEM_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right',
          render: props => {
            return <span>{Number(props.row.ADD_ITEM_AMOUNT).toFixed(2)}</span>;
          }
        },
        {
          title: '结算打印时间',
          dataIndex: 'PRINT_BALANCE_TIME',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm'
        },
        {
          title: '故障描述',
          dataIndex: 'RO_TROUBLE_DESC',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '证件号码',
          dataIndex: 'CERTIFICATE_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '上次保养日期',
          dataIndex: 'LAST_MAINTENANCE_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '上次保养里程',
          dataIndex: 'LAST_MAINTENANCE_MILEAGE',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        // {
        //   title: '车间反馈',
        //   dataIndex: 'EWORKSHOP_REMARK',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '索赔单号',
        //   dataIndex: 'CLAIM_NO',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '保险公司',
          dataIndex: 'INSURATION_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: 'FD上传',
        //   dataIndex: 'FD_STATUS',
        //   sorter: true,
        //   filter: true,
        //   hidden: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1004'),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.FD_STATUS, '1004')}</span>;
        //   }
        // },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电子首保卡备注',
          dataIndex: 'REMARK1',
          sorter: true,
          filter: true,
          filterType: 'input',
          hidden: true
        },
        {
          title: '是否修改预交车日期',
          dataIndex: 'IS_UPDATE_END_TIME_SUPPOSED',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '车辆销售日期',
          dataIndex: 'SALES_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD'
        }
      ];
    },
    electronization() {
      if (!this.selectColumns.length) {
        this.$notify.warning({ title: '提示信息', message: '请选择打印对象' });
      } else {
        this.getPrintData();
      }
    },
    // 获取工单打印数据
    async getPrintData() {
      let roNoList = []; // 工单号
      let vinList = []; // vin码
      let repairTypeList = []; // 维修类型
      let roNos = '';

      this.selectColumns.map(item => {
        roNoList.push(item.RO_NO);
        if (roNos == '') {
          roNos = "'" + item.RO_NO + "'";
        } else {
          roNos = roNos + ",'" + item.RO_NO + "'";
        }
        vinList.push(item.VIN);
        repairTypeList.push(item.REPAIR_TYPE_NAME);
        if (item.REPAIR_TYPE_CODE == 'S' || item.REPAIR_TYPE_CODE == 'Z') {
        } else {
          return notifyAction('只有“市场服务”与“召回”类型的工单，可以合并打印', 'warning');
          return;
        }
      });
      let deWeightVinList = [...new Set(vinList)];
      let deWeightRepariList = [...new Set(repairTypeList)];
      if (deWeightVinList.length > 1) {
        return notifyAction('不同车辆不能合并打印', 'warning');
        return;
      }
      if (deWeightRepariList.length > 1) {
        return notifyAction('维修类型不同不能合并打印', 'warning');
        return;
      }
      // 请求打印数据
      let totalData = '', // 获取工单信息及客户数据
        orderData = [], // 结算单详情
        remarkParams = []; // 说明

      // 获取工单信息及客户数据
      try {
        totalData = await getRepairOrderHBPrintInfo(roNos);
      } catch (err) {
        console.log(err, '获取工单信息失败');
      }

      try {
        let roNosList = [];
        roNoList.map((item, index) => {
          roNosList.push(item);
        });
        let orderDataRes = await getRoLabourDtls({ roNos: roNosList.join(',') });
        if (orderDataRes.resultCode == 200) {
          orderData = orderDataRes.data;
        }
      } catch (err) {
        console.log(err, '获取工单信息失败');
      }

      // 获取备件、项目以及金额数据

      this.printList = {
        ...totalData.data,
        orderData
      };
      let serviceMajordom = { role: dictCode.SERVE_MAJORDOM }; // 服务总监
      const serviceMajordomRes = await searchRoleByCode(serviceMajordom);
      if (serviceMajordomRes.data.length > 0) {
        this.printList.repairOrderMainInfo.SERVE_MAJORDOM = serviceMajordomRes.data[0].employeeName;
      }
      let allUserList = await getAllUser();
      allUserList.data.map(x => {
        if (x.userId + '' === this.printList.repairOrderMainInfo.TECHNICIAN) {
          this.printList.repairOrderMainInfo.TECHNICIAN = x.employeeName;
        }
        if (x.userId + '' === this.printList.repairOrderMainInfo.CREATED_BY) {
          console.log(this.printList.repairOrderMainInfo.CREATED_BY, 'zzzzzzzzzzzz');
          this.printList.repairOrderMainInfo.CREATED_BY = x.employeeName;
        }
      });
      let consultant = { role: dictCode.SERVICE_CONSULTANT }; // 服务顾问
      const consultantRes = await searchRoleByCode(consultant);
      consultantRes.data.map(x => {
        if (this.printList.repairOrderMainInfo.SERVICE_ADVISOR === x.userId + '') {
          this.printList.repairOrderMainInfo.SERVICE_ADVISOR = x.employeeName;
        }
      });

      this.printList.roNoList = roNoList;

      this.$refs.print.EXCUTE_PRINT();
    },
    async getUser() {
      this.ownerName = await getUser();
    },
    async getportal() {
      // 获取portal的参数
      let that = this;
      let allCookie = document.cookie.split(';');
      let role = '';
      allCookie.forEach(x => {
        if (x.indexOf('roleType') > -1) {
          role = x.split('=')[1];
        }
        if (x.indexOf('ownerCode') > -1) {
          that.ownerCode = x.split('=')[1];
        }
      });
      let res = await getportal({ systemName: '', systemCode: 'portal', module: null, roleCode: role, account: '', status: '10031001' });
      if (res.data.length > 0) {
        let login = res.data[0];
        that.paramss.username = login.account; // 'SA22001R01' ;
        that.paramss.password = login.password; // 'AUfw3202' ;
      }
      that.visible2 = true; // 当请求回来时显示组件
    },
    // FD维护
    uploadBtn() {
      // 1.首先接收需要参数
      if (this.selectColumns.length > 0) {
        if (!this.paramss.username) {
          this.$notify.warning({ title: '提示信息', message: '请维护portal账号和密码' });
        }
        let dms_wxz = this.ownerCode; // 经销商代码
        let dms_role = 1; // 传1	登录人员角色（服务顾问）
        let dms_user = this.paramss.username; // 登录人员Portal帐号
        let dms_address = 'http://interface-audiep.faw-vw.com:9003/api/audi-ep-datacenter-repair/fdreceive/info'; // 返回DMS的地址
        let dms_wtsh = this.selectColumns[0].RO_NO; // 委托书号
        let dms_wtsdat = this.selectColumns[0].RO_CREATE_DATE; // 时间拆开年月日 委托书日期
        dms_wtsdat = moment(this.dms_wtsdat).format('YYYY-MM-DD');
        let dms_wtstim = moment(this.dms_wtsdat).format('HH:mm:ss'); // 时分秒  委托书时间
        let dms_scname = this.getUser();
        let dms_bodynr = this.selectColumns[0].VIN; // "底盘号";//
        let dms_montor = this.selectColumns[0].ENGINE_NO; // 发动机号
        let dms_clgs = '1'; // 车辆归属  奥迪有，红旗没有
        let dms_khms = this.selectColumns[0].CUSTOMER_DESC; // 客户描述
        let dms_zxkm = this.selectColumns[0].IN_MILEAGE; // 是出厂还是进场  行驶里程
        let dms_carnum = this.selectColumns[0].LICENSE; // 车牌号
        let dms_gzms = this.selectColumns[0].RO_TROUBLE_DESC; // 经销商描述   最后要同步客户描述？
        let dms_bjbs = '1'; // 道路救援？提示信息？
        let System = 'EP';
        let f = document.createElement('form'); // 表单
        f.style.display = 'none'; // 显示为none
        f.target = '_blank'; // 打开新页面
        f.action = 'https://portal.faw-vw.com/webapp1/postServlet'; // 地址
        f.method = 'post';
        f.innerHTML =
          '<input type ="hidden" name="address_type" value="1" >' +
          '<input type ="hidden" name="dms_wxz" value="' +
          dms_wxz +
          '" >' +
          '<input type ="hidden" name="dms_role" value="' +
          dms_role +
          '" >' +
          '<input type ="hidden" name="dms_user" value="' +
          dms_user +
          '" >' +
          '<input type ="hidden" name="dms_address" value="' +
          dms_address +
          '" >' +
          '<input type ="hidden" name="dms_wtsh" value="' +
          dms_wtsh +
          '" >' +
          '<input type ="hidden" name="dms_wtsdat" value="' +
          dms_wtsdat +
          '" >' +
          '<input type ="hidden" name="dms_wtstim" value="' +
          dms_wtstim +
          '" >' +
          '<input type ="hidden" name="dms_scname" value="' +
          dms_scname +
          '" >' +
          '<input type ="hidden" name="dms_bodynr" value="' +
          dms_bodynr +
          '" >' +
          '<input type ="hidden" name="dms_montor" value="' +
          dms_montor +
          '" >' +
          '<input type ="hidden" name="dms_clgs" value="' +
          dms_clgs +
          '" >' +
          '<input type ="hidden" name="dms_khms" value="' +
          dms_khms +
          '" >' +
          '<input type ="hidden" name="dms_zxkm" value="' +
          dms_zxkm +
          '" >' +
          '<input type ="hidden" name="dms_carnum" value="' +
          dms_carnum +
          '" >' +
          '<input type ="hidden" name="dms_gzms" value="' +
          dms_gzms +
          '" >' +
          '<input type ="hidden" name="dms_bjbs" value="' +
          dms_bjbs +
          '" >' +
          '<input type ="hidden" name="System" value="' +
          System +
          '" >';
        document.body.appendChild(f);
        f.submit();
      } else {
        this.$notify.warning({ title: '提示信息', message: '请选择一条数据' });
      }
    },
    // 是否禁用扩展查询按钮
    // exQueryBtnState(val) {
    //   this.isDisabled = !this.isDisabled;
    //   this.topFilterList.forEach(x => {
    //     if (
    //       x.fieldName === 'address' ||
    //       x.fieldName === 'zipCode' ||
    //       x.fieldName === 'eMail' ||
    //       x.fieldName === 'haveClaimTag' ||
    //       x.fieldName === 'reMark' ||
    //       x.fieldName === 'PROVINCE' ||
    //       x.fieldName === 'CITY' ||
    //       x.fieldName === 'DISTRICT'
    //     ) {
    //       x.disabled = this.isDisabled;
    //     }
    //   });
    // },

    // 是否启用交车时间
    openRangeDate(val) {
      +val == 1 ? (this.isOpenDate = false) : (this.isOpenDate = true);
      let openDate = this.topFilterList.find(x => x.fieldName === 'checkPreDeliverVehicleBeginDate|checkPreDeliverVehicleEndDate');
      openDate.disabled = this.isOpenDate;
      if (+val == 1) {
        this.isOpenDate = false;
        openDate.disabled = this.isOpenDate;
        openDate.initialValue = [moment().format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')];
      } else {
        this.isOpenDate = true;
        openDate.disabled = this.isOpenDate;
        openDate.initialValue = [];
      }
    },

    // 售前人员接口数据
    async serviceConsultant() {
      let consultant = { role: dictCode.SERVICE_CONSULTANT }; // 服务顾问
      let technician = { role: dictCode.TECHNICIAN }; // 指定技师
      const consultantRes = await searchRoleByCode(consultant);
      const technicianRes = await searchRoleByCodes(technician);
      // console.log(consultantRes,'consultantRes');
      // console.log(technicianRes,'technicianRes')
      this.topFilterList.find(x => x.fieldName === 'serviceAdvisor').itemList = consultantRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').filterItems = this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems = consultantRes.data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
      this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').dictItems = this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems = consultantRes.data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
      this.columns.find(x => x.dataIndex === 'CHIEF_TECHNICIAN').filterItems = this.columns.find(x => x.dataIndex === 'CHIEF_TECHNICIAN').editItems = technicianRes.data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      })); //  TECHNICIAN_UNITE
      this.columns.find(x => x.dataIndex === 'TECHNICIAN_UNITE').filterItems = this.columns.find(x => x.dataIndex === 'TECHNICIAN_UNITE').editItems = technicianRes.data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
    },

    // 获取维修项目类型
    async getWxtypeSelect() {
      const res = await getWxlxSelect();
      console.log('维修项目==============维修类型' + res);
      this.topFilterList.find(x => x.fieldName === 'repairTypeCode').itemList = res.data.map(x => ({
        value: x.REPAIR_TYPE_CODE,
        text: x.REPAIR_TYPE_NAME
      }));
      // this.columnsLabour.find(x => x.dataIndex === 'REPAIR_TYPE_CODE').editItems = this.columnsLabour.find(x => x.dataIndex === 'REPAIR_TYPE_CODE').filterItems = res.data.map(x => ({
      //   value: x.REPAIR_TYPE_CODE,
      //   text: x.REPAIR_TYPE_NAME
      // }));
    },

    // 获取品牌 ——下拉框
    async getBrand() {
      this.topFilterList.find(x => x.fieldName === 'brand').itemList = (await getPinpSelect()).data.map(x => ({ value: x.brandId + '', text: x.brandName }));
    },

    // 车系下拉框
    async getSeries(id) {
      this.topFilterList.find(x => x.fieldName === 'series').itemList = (await getChexSelect(id)).data.map(x => ({ value: x.seriesId + '', text: x.seriesName }));
    },

    // 车型下拉框
    async getCheModelSelect(brandCode, id) {
      this.topFilterList.find(x => x.fieldName === 'model').itemList = (await getCheModelSelect(brandCode, id)).data.map(x => ({ value: x.modelId + '', text: x.modelName }));
    },

    // 获取保险公司-下拉框
    async getBxgsSelect() {
      const res = await getBxgsSelect();
      this.topFilterList.find(x => x.fieldName === 'insuranceCompany').itemList = res.data.map(x => ({ value: x.INSURATION_CODE, text: x.INSURATION_NAME }));
    },

    // 品牌下拉框改变时
    changePinpSelect(id) {
      this.clearFormItem(this.topFilterList.find(x => x.fieldName === 'series'));
      this.clearFormItem(this.topFilterList.find(x => x.fieldName === 'model'));
      this.brandCode = id;
      if (!id) return;
      this.getSeries(id);
    },

    // 车系下拉框改变时
    changeChexSelect(id) {
      this.clearFormItem(this.topFilterList.find(x => x.fieldName === 'model'));
      if (!id) return;
      this.getCheModelSelect(this.brandCode, id);
    },

    // 清空下拉框表当控件的值和下拉列表
    clearFormItem(item) {
      item.initialValue = undefined;
      item.itemList = [];
    },

    getBusiness(val) {
      if (val.dataBeginDate && val.dataEndDate) {
        let beginDate = moment(val.dataBeginDate).format('YYYY-MM-DD');
        let endDate = moment(val.dataEndDate).format('YYYY-MM-DD');
        val.dataBeginDate = beginDate;
        val.dataEndDate = endDate;
      }
      if (val.checkPreDeliverVehicleBeginDate && val.checkPreDeliverVehicleEndDate) {
        let beginDate = moment(val.checkPreDeliverVehicleBeginDate).format('YYYY-MM-DD');
        let endDate = moment(val.checkPreDeliverVehicleEndDate).format('YYYY-MM-DD');
        val.datcheckPreDeliverVehicleBeginDateaBeginDate = beginDate;
        val.checkPreDeliverVehicleEndDate = endDate;
      }

      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    },

    repairLabour(row) {
      this.selectData = row;
      this.labour = true;
    },

    // async getProvine() {
    //   const res = await getProvince();
    //   this.topFilterList.find(item => item.fieldName === 'PROVINCE').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    // },

    // // 省份改变
    // async provinceChange(regionId) {
    //   this.clearFormItem(this.topFilterList.find(item => item.fieldName === 'CITY'));
    //   this.clearFormItem(this.topFilterList.find(item => item.fieldName === 'DISTRICT'));
    //   if (!regionId) return;
    //   const res = await getCitys(regionId);
    //   this.topFilterList.find(item => item.fieldName === 'CITY').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    // },

    // // 市改变
    // async cityChange(regionId) {
    //   this.clearFormItem(this.topFilterList.find(item => item.fieldName === 'DISTRICT'));
    //   if (!regionId) return;
    //   const res = await getDistrict(regionId);
    //   this.topFilterList.find(item => item.fieldName === 'DISTRICT').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    // },

    collapseHandle() {
      this.$nextTick(() => {});
    },

    closeDialog() {
      this.claim = false;
      this.labour = false;
    },

    claimClick() {
      if (this.selectColumns.length) {
        this.claim = true;
      } else {
        this.$notify({
          title: '操作结果',
          message: '请先单击选中一条记录！',
          type: 'error'
        });
      }
    },

    async orderClick() {
      if (this.selectColumns.length) {
        const roNo = this.selectColumns[0].RO_NO;
        const res = await unLockRepairOrder(roNo);
        // console.log('res', res)
        if (res.resultCode === 200) {
          this.$notify({
            title: '操作结果',
            message: res.data + '!',
            type: 'success'
          });
        }
      } else {
        this.$notify({
          title: '操作结果',
          message: '请先单击选中一条记录！',
          type: 'error'
        });
      }
    },

    // 日志
    orderLogClick() {
      if (this.selectColumns.length) {
        this.orderLog = true;
      } else {
        this.$notify({
          title: '操作结果',
          message: '请先单击选中一条记录！',
          type: 'error'
        });
      }
    },

    // 关闭日志
    closeOrderLog() {
      this.orderLog = false;
    },

    // 导出
    exportClick() {
      repairBussinessExportExcel(this.fetchParams).then(res => {
        exportExcelFile(res, '维修业务查询');
      });
    },

    // 获取系统默认参数
    async getSystemDefaultValueInfo() {
      let params = { itemCode: 1063 };
      let res = await getSystemDefault(params);
      this.systemDefalutParams.yjcylTime = res.data; //  预交车预留时间
      this.systemDefalutParams.orderStatus = (await getSystemDefault({ itemCode: 8033 })).data; // 判断一车一单
      if (this.systemDefalutParams.orderStatus == '10041001') {
        this.columns.find(x => x.dataIndex === 'FD_STATUS').hidden = false;
        this.columns.find(x => x.dataIndex === 'EFW_CARD').hidden = false;
        this.columns.find(x => x.dataIndex === 'REMARK1').hidden = false;
        this.topFilterList.find(x => x.dataIndex === 'efwcard').hidden = false;
        this.topFilterList.find(x => x.dataIndex === 'remark1').hidden = false;
      }
    },

    // 获取表格所有数据
    async syncDataChange(val) {
      let repairDaysList = [];
      console.log(val, 'vallll');
      val.forEach(x => {
        // 判断FD上传状态改变颜色——————作者：gjp
        if (x.FD_STATUS == '10041002' && this.systemDefalutParams.orderStatus == '10041002') {
          if (x.REPAIR_TYPE_CODE == '1' || x.REPAIR_TYPE_CODE == 'G') {
            console.log('resss++++++=========', this.systemDefalutParams.orderStatus);
            let oldTime = moment(x.CREATED_AT).format('x'); // 创建时间
            console.log('创建时间', oldTime);
            let nowTime = moment().format('x'); // 现在时间
            console.log('创建时间', nowTime);
            let durahour = (nowTime - oldTime) / 1000 / 60 / 60; // FD相差两小时
            if (durahour < 1) {
              this.styleList.push({ row: x, styles: { color: 'red' } });
            } else {
              this.fetchRowstyles.push({ row: x, dataIndex: 'FD_STATUS', styles: { color: 'red' } });
            }
          }
        }
      });
      let momentDate = new Date();
      // 当前系统时间-约定交车时间>预交车预留时间 且未提交结算的，红底显示。
      // 当工单含快修标志时，当前系统时间-开单时间>60分钟，且未提交结算的，红底显示 工单状态

      val.forEach(x => {
        let endTimeSupposed = x.END_TIME_SUPPOSED; // 约定交车时间
        if (this.systemDefalutParams.yjcylTime < momentDate - endTimeSupposed) {
          console.log(x, 'xxxxxxx');
          if (x.RO_STATUS !== '80491002' || x.RO_STATUS !== '80491003') {
            console.log(222);
            this.styleList.push({ row: x, styles: { backgroundColor: '#FBE1E3' } });
          }
        }
        // else if (x.REPAIR_DAYS >= 5 && x.REPAIR_DAYS <= 9) {
        //   this.styleList.push({ row: x, styles: { backgroundColor: '#F9E491' } });
        // }
      });
    },

    // closeHandler(val, type) {
    //   this.visible = val;
    //   if (type === 'refresh') {
    //     // 重新加载
    //     this.fetchParams = { ...this.fetchParams };
    //   }
    // }

    // 验证系统参数状态并做相应设置
    checkSystemOptionAuthParams() {
      // 是否可以到处excel
      if (this.systemOptionAuthParams.isCanExportExcel === '10041002') {
        this.btnExportType = false;
      }
    }
  }
};
</script>

<style lang="less" scoped>
p {
  font-size: 14px;
  padding-top: 24px;
  color: #ed6b75;
}
</style>
